<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>学生-课堂-任务</title>
<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/classTask-stu.css'/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<script src="<c:url value='/js/classTaskStu.js'/>" type="text/javascript" charset="utf-8"></script>
</head>
<body>	
	<div class="container-fluid main">
		<%@include file="/common/header.jsp"%>
		<%@include file="lessonHeader.jsp"%>
		<div class="row">
			<div class="col-md-1"></div>
			<div class="col-xs-12 col-sm-12 col-md-10">
				<%@include file="lessonNav.jsp"%>
				<div class="row" id="task-list">
					<!-- 任务列表 -->
					<div class="col-md-12">
						<table class="table table-hover" id="lesson-table-pc">
							<thead>
								<tr>
									<th>
										<select class="form-control" id="selectType" onchange="search()">
											<option selected = "selected" value="ALL">全部</option>
											<option value="ASKINLESSON">课堂提问</option>
											<option value="TESTINLESSON">当堂测试</option>
											<option value="HOMEWORK">课后作业</option>
											<option value="LABTEST">实验任务</option>
										</select>
									</th>
									<th>任务名</th>
									<th>截止时间</th>
									<th>发布者</th>
									<th>状态</th>
								</tr>
							</thead>
							<tbody id="taskList">
								
							</tbody>
						</table>
						
						<table class="table table-hover" id="lesson-table-mobile">
							<thead>
								<tr>
									<th>任务名</th>
									<th>截止时间</th>
								</tr>
							</thead>
							<tbody id="taskList1">
								
							</tbody>
						</table>
						
					</div>
				</div>
						
				<!-- 任务详情 -->
				<div id="task-detail">
					<!-- 任务信息 -->
					<%@include file="taskDetail.jsp"%>
				</div>
				
			</div>
			<div class="col-md-1"></div>
		</div>
		
	</div>
	<%@include file="/common/footer.jsp"%>
</body>
<script>
var data=${data};
$(document).ready(function() {
	if (data.status != "success") {
		alert(data.message);
		return;
	};
	$("#task").css("color","#00b43c");
	initLesson(data.data.lesson);
	initTaskList(data.data.list);
	changeStuLessonUrl(data.data.lesson.classId);
 });

 var initTaskList=function(list){
	 var taskList=$("#taskList");
	 var taskList1=$("#taskList1");
	 taskList.empty();
	 taskList1.empty();
	 if(list.length <= 0){
		 var s = "<tr><td colspan=\"5\">暂无任务记录</td></tr>";
		 var s1 = "<tr><td colspan=\"2\">暂无任务记录</td></tr>";
		 taskList.append(s);
		 taskList1.append(s1);
	 }else{
		 for(var i=0;i<list.length;i++){
			 var item=list[i];
			 var s="";
			 var s1="";
			 if(item.type=="ASKINLESSON") {
				 s+="<tr bgcolor=\"#D2F2DA\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
				 s+="<td title=\""+getTaskType(item.type)+"\">"+getTaskType(item.type)+"</td>";
				 s+="<td title=\""+item.title+"\">"+item.title+"</td>";
				 s+="<td>---</td>";
				 s+="<td title=\""+item.createName+"\">"+item.createName+"</td>";
				 s+="<td>---</td>";
				 
				 s1+="<tr bgcolor=\"#D2F2DA\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
				 s1+="<td title=\""+item.title+"\">"+item.title+"</td>";
				 s1+="<td>---</td>";
			 }else {
				 s+="<tr bgcolor=\""+setColor(item.taskStatus)+"\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
				 s+="<td title=\""+getTaskType(item.type)+"\">"+getTaskType(item.type)+"</td>";
				 s+="<td title=\""+item.title+"\">"+item.title+"</td>";
				 s+="<td title=\""+item.deadline+"\">"+item.deadline+"</td>";
				 s+="<td title=\""+item.createName+"\">"+item.createName+"</td>";
				 s+="<td title=\""+getStatus(item.taskStatus)+"\">"+getStatus(item.taskStatus)+"</td>";
				 
				 s1+="<tr bgcolor=\""+setColor(item.taskStatus)+"\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
				 s1+="<td title=\""+item.title+"\">"+item.title+"</td>";
				 s1+="<td title=\""+item.deadline+"\">"+item.deadline+"</td>";
			 }
			 

			 s+="</tr>";
			 taskList.append(s);

			 s1+="</tr>";
			 taskList1.append(s1);
		 }
	 }
	 
 };
var getStatus  = function(status){
	if(status=="UNCOMMITTED"){
		return "未提交";
	}else if(status=="COMMITTED"){
		return "已提交";
	}else{
		return "已批改";
	}
}

var setColor = function(status){
	if(status=="UNCOMMITTED"){
		return "#F2CECE";
	}else if(status=="COMMITTED"){
		return "#F4EED6";
	}else if(status=="HAVEREAD"){
		return "#D2F2DA";
	}else{
		return ;
	}
};
 
var getTaskType = function(type){
	if(type=="ASKINLESSON"){
		return "课堂提问";
	}else if(type=="TESTINLESSON"){
		return "当堂测试";
	}else if(type=="HOMEWORK"){
		return "课后作业";
	}else if(type=="LABTEST"){
		return "实验任务";
	}else{
		return "其他";
	}
}
var search = function(){
	
	var type=$("#selectType option:selected").val();
	console.log(type);
	var json={
			lessonId:data.data.lesson.id,
			type:type
	};
	if(type=="ALL"){
		delete json.type;
	}
	initTask(json);
}

var initTask = function(json){
	$.get(CONTEXT_PATH+"lessonTaskView/ajaxStuView", {
		data : JSON.stringify(json)
	}, function(data) {		
		if(data.status=="success"){
			initTaskList(data.data.list);
		}else{
			alert(data.message);
		}
	});
}
</script>
</html>